﻿using System;

namespace Hukee.ExcelHelper
{
    /// <summary>
    /// Excel列定义
    /// </summary>
    [AttributeUsage(AttributeTargets.Property,AllowMultiple = false)]
    public class ExcelColumn : Attribute
    {
        /// <summary>
        /// 第几列
        /// </summary>
        public int CloumnNumber { get; set; }

        /// <summary>
        /// 所属列名
        /// </summary>
        public string ColumnName { get; set; }

        public ExcelColumn(int number, string name)
        {
            CloumnNumber = number;
            ColumnName = name;
        }
    }

    /// <summary>
    /// Excel文件名称定义
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class ExcelFile : Attribute
    {
        /// <summary>
        /// 文件命名
        /// </summary>
        public string FileName { get; set; }

        public ExcelFile(string name)
        {
            if (!name.EndsWith("xlsx"))
            {
                name += ".xlsx";
            }
            FileName = name;
        }
    }

    /// <summary>
    /// Excel文件名称定义
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false)]
    public class ExcelSheet : Attribute
    {
        /// <summary>
        /// 文件命名
        /// </summary>
        public string SheetName { get; set; }

        public ExcelSheet(string name)
        {
            SheetName = name;
        }
    }

    /// <summary>
    /// 目标值转换
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class ExcelValueChanger : Attribute
    {
        /// <summary>
        /// 转换提交值
        /// </summary>
        public object Condition { get; set; }

        /// <summary>
        /// 转换后的值
        /// </summary>
        public string ChangeValue { get; set; }

        public ExcelValueChanger(object condition, string changeValue)
        {
            Condition = condition;
            ChangeValue = changeValue;
        }

        /*  使用例子如下：
            /// <summary>
            /// 系统申报类型  0-社保新增、1-社保续保、2-社保停保、3-社保变更、4-社保补缴、5-社保退保 6-公积金新增、7-公积金调入、8-公积金封存、9-公积金变更、10-公积金保补缴、11-公积金退保
            /// </summary>
            [ExcelColumn(9, "申报类型")]
            [ExcelValueChanger(0,"社保新增")]
            [ExcelValueChanger(1, "社保续保")]
            [ExcelValueChanger(2, "社保停保")]
            [ExcelValueChanger(3, "社保变更")]
            [ExcelValueChanger(4, "社保补缴")]
            [ExcelValueChanger(5, "社保退保")]
            [ExcelValueChanger(6, "公积金新增")]
            [ExcelValueChanger(7, "公积金调入")]
            [ExcelValueChanger(8, "公积金封存")]
            [ExcelValueChanger(9, "公积金变更")]
            [ExcelValueChanger(10, "公积金保补缴")]
            [ExcelValueChanger(11, "公积金退保")]
            public int ApplyType { get; set; }


            当ApplyType=0值的时候，做Excel生成时会把值变更为 “社保新增” 而不是 0
         */
    }

    /// <summary>
    /// 字符串输出格式化 比如 <br/>
    /// 日期可以："yyy-MM-dd HH:mm:ss" <br/>
    /// 小数可以： "#0.00" 做小数位保留 等。
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class ExcelStringFormate : Attribute
    {
        /// <summary>
        /// 转换提交值
        /// </summary>
        public string Formate { get; set; }

        public ExcelStringFormate(string formate)
        {
            Formate = formate;
        }

        /* 使用例子如下：

            /// <summary>
            /// 受理时间
            /// </summary>
            [ExcelColumn(8, "受理时间")]
            [ExcelDateTimeFormate("yyyy-MM-dd HH:mm:ss")]
            public DateTime AcceptTime { get; set; }

            对时间进行格式化输出限制

        
        
            /// <summary>
            /// 金额
            /// </summary>
            [ExcelColumn(7, "金额")]
            [ExcelDateTimeFormate("#0.0000")]
            public double Money { get; set; }

            对小数进行格式化输出限制 （float\double\decimal）


         */
    }

    /// <summary>
    /// Excel样式设置
    /// </summary>
    [AttributeUsage(AttributeTargets.Property,AllowMultiple = true)]
    public class ExcelStyle : Attribute
    {
        /// <summary>
        /// 设置的对象信息<br/>
        /// Title（标题单元格）<br/>
        /// Normal(数据单元格)
        /// </summary>
        public FormatType ToFormat { get; set; } = FormatType.Normal | FormatType.Title;

        /// <summary>
        /// 字体名称<br/>
        /// 默认字体为"宋体"<br/>
        /// * 设置的名称要和Excel里面的字体名称对应，否则会报错
        /// </summary>
        public string FontName { get; set; } = "宋体";

        /// <summary>
        /// 字体大小
        /// </summary>
        public short FontSize { get; set; } = 11;

        /// <summary>
        /// 是否斜体
        /// </summary>
        public bool IsItalic { get; set; } = false;

        /// <summary>
        /// 是否有删除线
        /// </summary>
        public bool IsStrikeout { get; set; } = false;

        /// <summary>
        /// 是否加粗
        /// </summary>
        public bool IsBold { get; set; } = false;

        /// <summary>
        /// 下划线
        /// </summary>
        public ExcelUnderLineType ExcelUnderLineType { get; set; } = ExcelUnderLineType.None;

    }

    public enum ExcelUnderLineType
    {
        None = 0,
        Single = 1,
        Double = 2,
        SingleAccounting = 33,
        DoubleAccounting = 34
    }

    public enum FormatType
    {
        Title = 1,
        Normal = 1<<1
    }

}
